package com.leyou.item.service.iml;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.entity.Category;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Serviceiimpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Override
    public List<CategoryDTO> queryCategoryByBid(Long pid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent_id",pid);
       // List<Category> list=list(queryWrapper);
        /*+
        * query()相当于select * from,eq就是where后面的条件
        * */
        //开启了一个链式编程
        List<Category> parent_id = query().eq("parent_id", pid).list();

        return CategoryDTO.convertEntityList(parent_id);
    }

    @Override
    public CategoryDTO queryCategoryByid(Long id) {
        Category byId = getById(id);

        return new CategoryDTO(byId);
    }

    /*根据分类ids查分类集合*/
    @Override
    public List<CategoryDTO> queryCategoryByIds(List<Long> ids) {
        //entity转换为dto
        return CategoryDTO.convertEntityList(listByIds(ids));
    }


}
